package com.wudimeng.syll.controller.api;


import com.wudimeng.syll.common.ApiResponse;
import com.wudimeng.syll.constants.Constant;
import com.wudimeng.syll.entity.CRuKuXinXi;
import com.wudimeng.syll.entity.LiuRuLiuChuDuiXiang;
import com.wudimeng.syll.service.ICRuKuXinXiService;
import com.wudimeng.syll.service.ILiuRuLiuChuDuiXiangService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author laohei
 * @Date 2020/6/8 9:50
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("syll")
public class LiuRuLiuChuDuiXiangController {

    @Autowired
    private ILiuRuLiuChuDuiXiangService service;

    @GetMapping("/LiuRuLiuChuDuiXiang")
    public ApiResponse getLiuRuLiuChuDuiXiang(HttpServletRequest request){
        try {
            Map<String,String> map = new HashMap<>();
            map.put("WeiTuoID",request.getParameter("WeiTuoID"));
            map.put("YongHuID",request.getParameter("YongHuID"));
            map.put("GongYingShangHuoXiaoSHouDuiXiang",request.getParameter("GongYingShangHuoXiaoSHouDuiXiang"));
            map.put("QiYeMingCheng",request.getParameter("QiYeMingCheng"));
            return this.service.selectLiuRuLiuChuDuiXiang(map);
        } catch (Exception e) {
            log.error("LiuRuLiuChuDuiXiangController.getLiuRuLiuChuDuiXiang.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_PARAMETER_DEGRADE);
        }
    }

    @GetMapping("/getLiuRuLiuChuDuiXiang")
    public ApiResponse getLiuRuLiuChuDuiXiangByID(HttpServletRequest request){
        try {
            return this.service.selectLiuRuLiuChuDuiXiangByID(request.getParameter("ID"));
        } catch (Exception e) {
            log.error("LiuRuLiuChuDuiXiangController.getLiuRuLiuChuDuiXiang.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_PARAMETER_DEGRADE);
        }
    }


    @PostMapping("/LiuRuLiuChuDuiXiang")
    public ApiResponse addLiuRuLiuChuDuiXiang(@RequestBody LiuRuLiuChuDuiXiang liuRuLiuChuDuiXiang, HttpServletRequest request){
        try {
            service.addLiuRuLiuChuDuiXiang(liuRuLiuChuDuiXiang);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(Constant.COMMON_INSERT_FAIL);
        }
        return ApiResponse.success(Constant.COMMON_INSERT_SUCCESS);
    }

    @PutMapping("/LiuRuLiuChuDuiXiang")
    public ApiResponse updLiuRuLiuChuDuiXiang(@RequestBody LiuRuLiuChuDuiXiang liuRuLiuChuDuiXiang, HttpServletRequest request){
        try {
            service.updLiuRuLiuChuDuiXiang(liuRuLiuChuDuiXiang);
        } catch (Exception e) {
            e.printStackTrace();
            return ApiResponse.error(Constant.COMMON_UPDATE_FAIL);
        }
        return ApiResponse.success(Constant.COMMON_UPDATE_SUCCESS);
    }

    @DeleteMapping("/LiuRuLiuChuDuiXiang")
    public ApiResponse delLiuRuLiuChuDuiXiangByID(HttpServletRequest request){
        try {
            service.delLiuRuLiuChuDuiXiang(request.getParameter("ID"));
        } catch (Exception e) {
            log.error("LiuRuLiuChuDuiXiangController.getLiuRuLiuChuDuiXiang.请稍后再试:" + e.getMessage());
            return ApiResponse.error(Constant.COMMON_DELETE_FAIL);
        }
        return ApiResponse.success(Constant.COMMON_DELETE_SUCCESS);
    }
}
